package down.sallai.ml.controller;

import down.sallai.ml.services.ProxyService;
import down.sallai.ml.util.okhttp.GetUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: $
 * @author: sallai
 * @time: 2022年1月3日 0003 下午 07:27:42 秒
 */
@Controller
@RestController
@Slf4j
public class GithubProxy {

    @Autowired
    GetUtils getUtils;


    @Autowired
    ProxyService proxyService;

    @RequestMapping("/**")
    public void proxyGetMethod(HttpServletRequest request, HttpServletResponse response) {
        String requestURI = request.getRequestURI();
        if( null != request.getQueryString()) {
            requestURI+= "?"+request.getQueryString();
        }
        //change the url path
//        requestURI = requestURI.replaceAll("/github","");
        log.info("Get 请求路径->"+requestURI);
        proxyService.proxy(requestURI);
    }
}
